package com.zyf.audio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by hp on 2021/10/15.
 */
public class MyServer {
    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        Socket socket = null;
        try {
            //启动服务
            serverSocket =  new ServerSocket(8888);
            while(true){
                System.out.println("server已经启动等待连接...............");
                socket = serverSocket.accept();

                String  address = socket.getInetAddress().getHostAddress();
                System.out.println("地址是"+address);
                //启动线程获取数据并发送数据
                SendThread st  = new SendThread(socket);
                st.setName(address);
                st.start();

                ReceiceThread rt = new ReceiceThread(socket);
                rt.setName(address);
                rt.start();
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (serverSocket!=null) serverSocket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
